package com.edu.modules.baseinfo.api;

import com.alibaba.fastjson.JSONObject;
import com.edu.modules.baseinfo.service.LessonService;
import com.edu.modules.baseinfo.vo.*;
import com.sari.common.utils.RequestContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author kwj
 * @version 2016-08-01
 */
@CrossOrigin
@Controller
@RequestMapping(value = "lesson")
public class LessonApi {

    @Autowired
    private LessonService lessonService;

    @ResponseBody
    @RequestMapping(value = "save")
    public ResultVo saveLesson(HttpServletRequest request){

        JSONObject param = RequestContextUtils.readJson(request);
        return lessonService.saveLesson(param);
    }
    
    @ResponseBody
    @RequestMapping(value = "list")
    public LessonListVo getLessonList(String lessonName,String lessonClass) {

        return new LessonListVo(lessonService.getLessonList(lessonName,lessonClass));
    }

    @ResponseBody
    @RequestMapping(value = "lessonDetail")
    public LessonDetailVo getLessonDetail(String lessonId) {

        return new LessonDetailVo(lessonService.getLessonDetail(lessonId));
    }

    @ResponseBody
    @RequestMapping(value = "videoList")
    public LessonVideoListVo getLessonRecordListByCode(String code) {

        return lessonService.getLessonRecordListByCode(code);
    }

    @ResponseBody
    @RequestMapping(value = "myVideoList")
    public LessonVideoListVo getLessonRecordList(String studentId) {

        return lessonService.getLessonVideoList(studentId);
    }

    @ResponseBody
    @RequestMapping(value = "my")
    public MyLessonListVo getMyLessonList(String studentId) {

        return lessonService.getMyLessonList(studentId);
    }

    @ResponseBody
    @RequestMapping(value = "getLessonGroup")
    public JSONObject getLessonGroup() {
        return lessonService.getLessonGroup();
    }

    @ResponseBody
    @RequestMapping(value = "getTeacherLessonGroup")
    public JSONObject getTeacherLessonGroup(HttpServletRequest request) {
        JSONObject param = RequestContextUtils.readJson(request);
        return lessonService.getTeacherLessonGroup(param);
    }

    @ResponseBody
    @RequestMapping(value = "getLessonByPage")
    public JSONObject getLessonByPage(HttpServletRequest request) {

        JSONObject param = RequestContextUtils.readJson(request);
        return lessonService.getLessonByPage(param);
    }

    @ResponseBody
    @RequestMapping(value = "getLessonWeeks")
    public JSONObject getLessonWeeks(String lessonId){

        return lessonService.getLessonWeeks(lessonId);
    }

    @ResponseBody
    @RequestMapping(value = "update")
    public JSONObject updateLesson(HttpServletRequest request){
        JSONObject param = RequestContextUtils.readJson(request);
        lessonService.updateLesson(param);
        JSONObject result = new JSONObject();
        result.put("msg","数据更新成功");
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "delete")
    public ResultVo deleteLesson(String lessonId) {

        return lessonService.deleteLesson(lessonId);
    }

    @ResponseBody
    @RequestMapping(value = "calendar")
    public JSONObject getLessonCalendar(String studentId,String dateTime) {

        return lessonService.getLessonCalendar(studentId,dateTime);
    }

    @ResponseBody
    @RequestMapping(value = "myLesson")
    public JSONObject getMyLesson(String studentId,String dateTime) {

        return lessonService.getMyLesson(studentId,dateTime);
    }
}
